home *** CD-ROM | disk | FTP | other *** search
- {**********************************************************************
-
- MDI Example Program $Version$
- $Author$ $Date$
-
- Copyright (c) 1991 Anthony M. Vitabile.
- All rights reserved.
-
- Permission is hereby granted to all who desire to use this
- source code in their programs provided the above copyright
- is included in the program.
-
- Program Description
-
- This program is a demonstration of how to use the object types
- defined in the MDITypes unit. It defines four possible types
- MDI children, all of which are descended from TMDIChild or
- TMDIDialog. It shows how to create MDI child windows which
- look and act like modeless dialog boxes, as well as to do some
- more conventional acts like drawing on an MDI child and editing
- text in one.
-
- **********************************************************************}
-
- {$R MDIEXAM.RES}
- program MDIExample;
- Uses MDITypes, WinTypes, WinProcs, WObjects, Strings;
-
- {$D 'Copyright (c) 1991 Anthony M. Vitabile'}
- {$I MDIEXAM.INC}
-
- const
- AppName = 'MDIExample';
- Dlg1Name = 'Dialog1';
- Dlg2Name = 'Dialog2';
- EditName = 'MDIEdit';
- RandName = 'MDIRect';
-
- EditPos = 2;
- InitPos = 1;
- RectPos = 1;
-
- type
- ChildNames = (Dialog1, Dialog2, RandRect, EditCtrl);
-
- TitleArray = array [Dialog1 .. EditCtrl] of PChar;
-
- PDialog1 = ^TDialog1;
- PDialog2 = ^TDialog2;
- PDlg1XferBuffer = ^Dlg1XferBuffer;
- PDlg2XferBuffer = ^Dlg2XferBuffer;
- PMDIApplication = ^TMDIApplication;
- PMDIDialog1 = ^TMDIDialog1;
- PMDIDialog2 = ^TMDIDialog2;
- PMDIEditChild = ^TMDIEditChild;
- PMyMDIFrame = ^TMyMDIFrame;
- PRandRect = ^TRandRect;
-
- Dlg1XferBuffer = record
- Number : array [0 .. 6] of char;
- Name ,
- Company,
- Address,
- City : array [0 .. 40] of char;
- State : array [0 .. 3] of char;
- ZipCode: array [0 .. 11] of char
- end;
-
- Dlg2XferBuffer = record
- Number: array [0 .. 6] of char;
- Field1: array [0 .. 40] of char;
- Field2: array [0 .. 80] of char
- end;
-
- TDialog1 = object (TDlgWindow)
- Static : PStatic;
- Name ,
- Company,
- Address,
- City ,
- State ,
- ZipCode: PEdit;
-
- destructor Done;
- virtual;
- constructor Init(AParent: PWindowsObject;
- AName : PChar;
- Buffer : Pointer);
- end;
-
- TDialog2 = object (TDlgWindow)
- Static: PStatic;
- Field1,
- Field2: PEdit;
-
- destructor Done;
- virtual;
- constructor Init(AParent: PWindowsObject;
- AName : PChar;
- Buffer : Pointer);
- end;
-
- TMDIApplication = object (TApplication)
- EditMenu,
- RectMenu: HMenu;
-
- destructor Done;
- virtual;
- procedure InitInstance;
- virtual;
- procedure InitMainWindow;
- virtual;
- function ProcessAppMsg(var Message: TMsg): boolean;
- virtual;
- end;
-
- TMDIDialog1 = object (TMDIDialog)
- destructor Done;
- virtual;
- constructor Init(AParent: PWindowsObject;
- ATitle : PChar;
- ANumber: integer);
- function InitDialog: PDlgWindow;
- virtual;
- function GetClassName: PChar;
- virtual;
- procedure GetWindowClass(var AWndClass: TWndClass);
- virtual;
- procedure SetupWindow;
- virtual;
- procedure wmInitMenuPopup(var Msg: TMessage);
- virtual wm_First + wm_InitMenuPopup;
- end;
-
- TMDIDialog2 = object (TMDIDialog)
- destructor Done;
- virtual;
- constructor Init(AParent: PWindowsObject;
- ATitle : PChar;
- ANumber: integer);
- function InitDialog: PDlgWindow;
- virtual;
- function GetClassName: PChar;
- virtual;
- procedure GetWindowClass(var AWndClass: TWndClass);
- virtual;
- procedure SetupWindow;
- virtual;
- procedure wmInitMenuPopup(var Msg: TMessage);
- virtual wm_First + wm_InitMenuPopup;
- end;
-
- TMDIEditChild = object(TMDIChild)
- TheEdit: PEdit;
-
- destructor Done;
- virtual;
- constructor Init(AParent: PWindowsObject;
- ATitle : PChar;
- ANumber: integer);
- function GetClassName: PChar;
- virtual;
- procedure GetWindowClass(var AWndClass: TWndClass);
- virtual;
- procedure wmInitMenuPopup(var Msg: TMessage);
- virtual wm_First + wm_InitMenuPopup;
- procedure wmSetFocus(var Msg: TMessage);
- virtual wm_First + wm_SetFocus;
- procedure wmSize(var Msg: TMessage);
- virtual wm_First + wm_Size;
- end;
-
- TMyMDIFrame = object (TMDIFrame)
- NoChildren: integer;
- DialogType: ChildNames;
-
- constructor Init(ATitle: PChar;
- APos : integer);
- function GetClassName: PChar;
- virtual;
- procedure GetWindowClass(var AWndClass: TWndClass);
- virtual;
- function InitChild: PWindowsObject;
- virtual;
- procedure SetupWindow;
- virtual;
- procedure idCloseChild(var Msg: TMessage);
- virtual cm_First + id_CloseChild;
- procedure idDialog1(var Msg: TMessage);
- virtual cm_First + id_Dialog1;
- procedure idDialog2(var Msg: TMessage);
- virtual cm_First + id_Dialog2;
- procedure idEditCtrl(var Msg: TMessage);
- virtual cm_First + id_EditCtrl;
- procedure idRandRect(var Msg: TMessage);
- virtual cm_First + id_RandRect;
- end;
-
- TRandRect = object (TMDIChild)
- constructor Init(AParent: PWindowsObject;
- ATitle : PChar;
- ANumber: integer);
- function GetClassName: PChar;
- virtual;
- procedure SetupWindow;
- virtual;
- procedure wmDestroy(var Msg: TMessage);
- virtual wm_First + wm_Destroy;
- procedure wmPaint(var Msg: TMessage);
- virtual wm_First + wm_Paint;
- procedure wmTimer(var Msg: TMessage);
- virtual wm_First + wm_Timer;
- end;
-
- const
- ChildTitles: TitleArray = ('Dialog 1, Child #',
- 'Dialog 2, Child #',
- 'Random Rectangles, Child #',
- 'Editor, Child #');
-
- var
- MDIApplication: TMDIApplication;
-
- {**********************************************************************
-
- This is a generic routine for initializing the Edit menu for
- any menu that has one and for any window that has an edit
- control. It checks the edit control to see if it's able
- to undo an edit, tests for text on the clipboard, etc.
-
- **********************************************************************}
-
- procedure InitEditMenu(Edit: HWnd; var Msg: TMessage);
- var
- Enable: word;
- Select: LongInt;
-
- begin { InitEditMenu }
- if SendMessage(Edit, em_CanUndo, 0, 0) <> 0
- then Enable := mf_Enabled
- else Enable := mf_Grayed;
- EnableMenuItem(Msg.wParam, cm_EditUndo , Enable or mf_ByCommand);
- if IsClipboardFormatAvailable(cf_Text)
- then Enable := mf_Enabled
- else Enable := mf_Grayed;
- EnableMenuItem(Msg.wParam, cm_EditPaste, Enable or mf_ByCommand);
- Select := SendMessage(Edit, em_GetSel, 0, 0);
- if LoWord(Select) = HiWord(Select)
- then Enable := MF_Grayed
- else Enable := MF_Enabled;
- EnableMenuItem(Msg.wParam, cm_EditCut , Enable or mf_ByCommand);
- EnableMenuItem(Msg.wParam, cm_EditCopy , Enable or mf_ByCommand);
- EnableMenuItem(Msg.wParam, cm_EditClear, Enable or mf_ByCommand);
- Msg.result := 0
- end { InitEditMenu };
-
- {**********************************************************************
-
- TDialog1 methods
-
- Done destructor. This method frees all child objects
- associated with the dialog box instance and then destroys
- itself.
-
- **********************************************************************}
-
- destructor TDialog1.Done;
- begin { TDialog1.Done }
- dispose(Static , Done);
- dispose(Name , Done);
- dispose(Address, Done);
- dispose(Company, Done);
- dispose(City , Done);
- dispose(State , Done);
- dispose(ZipCode, Done);
- TDlgWindow.Done
- end { TDialog1.Done };
-
- {**********************************************************************
-
- Init constructor. This method builds a modeless dialog box.
- It first calls TDlgWindow.Init to initialize all of the fields
- TDialog1 inherited. It then creates OWL child control objects
- that allow the activation of the transfer buffer feature.
-
- **********************************************************************}
-
- constructor TDialog1.Init(AParent: PWindowsObject;
- AName : PChar;
- Buffer : Pointer);
- begin { TDialog1.Init }
- TDlgWindow.Init(AParent, AName);
- TransferBuffer := Buffer;
- Static := New(PStatic, InitResource(@Self, id_ChildNumber, 6));
- Name := New(PEdit , InitResource(@Self, id_Name , 40));
- Company := New(PEdit , InitResource(@Self, id_Company , 40));
- Address := New(PEdit , InitResource(@Self, id_Address , 40));
- City := New(PEdit , InitResource(@Self, id_City , 40));
- State := New(PEdit , InitResource(@Self, id_State , 3));
- ZipCode := New(PEdit , InitResource(@Self, id_ZipCode , 11));
- Static ^.EnableTransfer;
- Name ^.EnableTransfer;
- Address^.EnableTransfer;
- Company^.EnableTransfer;
- City ^.EnableTransfer;
- State ^.EnableTransfer;
- ZipCode^.EnableTransfer;
- EnableKBHandler
- end { TDialog1.Init };
-
- {**********************************************************************
-
- TDialog2 methods
-
- Done destructor. This method frees all child objects
- associated with the dialog box instance and then destroys
- itself.
-
- **********************************************************************}
-
- destructor TDialog2.Done;
- begin { TDialog2.Done }
- dispose(Static, Done);
- dispose(Field1, Done);
- dispose(Field2, Done);
- TDlgWindow.Done
- end { TDialog2.Done };
-
- {**********************************************************************
-
- Init constructor. This method builds a modeless dialog box.
- It first calls TDlgWindow.Init to initialize all of the fields
- TDialog1 inherited. It then creates OWL child control objects
- that allow the activation of the transfer buffer feature.
-
- **********************************************************************}
-
- constructor TDialog2.Init(AParent: PWindowsObject;
- AName : PChar;
- Buffer : Pointer);
- begin { TDialog2.Init }
- TDlgWindow.Init(AParent, AName);
- TransferBuffer := Buffer;
- Static := New(PStatic, InitResource(@Self, id_ChildNumber, 6));
- Field1 := New(PEdit , InitResource(@Self, id_Field1 , 40));
- Field2 := New(PEdit , InitResource(@Self, id_Field2 , 80));
- Static^.EnableTransfer;
- Field1^.EnableTransfer;
- Field2^.EnableTransfer;
- EnableKBHandler
- end { TDialog2.Init };
-
- {**********************************************************************
-
- TMDIApplication methods
-
- Done destructor. This method frees the child menus we've
- created in the resource file & loaded. This procedure is
- called after the message loop has exitted, so all child windows
- that would use these menus are long dead.
-
- **********************************************************************}
-
- destructor TMDIApplication.Done;
- begin { TMDIApplication.Done }
- { DestroyMenu(EditMenu);
- DestroyMenu(RectMenu); }
- TApplication.Done
- end { TMDIApplication.Done };
-
- {**********************************************************************
-
- InitInstance. This method is called whenever an application
- starts running in order to perform initialization for the
- instance currently starting up. This method first loads
- the menus for the MDI child windows from the resource file.
- It then performs the rest of the instance initialization by
- calling the ancestor method.
-
- **********************************************************************}
-
- procedure TMDIApplication.InitInstance;
- begin { TMDIApplication.InitInstance }
- EditMenu := LoadMenu(HInstance, EditName);
- RectMenu := LoadMenu(HInstance, RandName);
- TApplication.InitInstance;
- HAccTable := LoadAccelerators(HInstance, AppName)
- end { TMDIApplication.InitInstance };
-
- {**********************************************************************
-
- This method creates the program's main window. In this case,
- this is the Frame window, descended from TMDIFrame. It creates
- the OWL window object & saves the pointer to it in the
- application object's MainWindow field.
-
- **********************************************************************}
-
- procedure TMDIApplication.InitMainWindow;
- begin { TMDIApplication.InitMainWindow }
- MainWindow := New(PMyMDIFrame, Init(AppName, InitPos))
- end { TMDIApplication.InitMainWindow };
-
- {**********************************************************************
-
- Performs special handling for the message last retrieved.
- Translates keyboard input messages into control selections or
- command messages, when appropriate. Dispatches message, if
- translated. This method changes the order in which testing
- is performed so that MDI accelerators are performed first.
-
- **********************************************************************}
-
- function TMDIApplication.ProcessAppMsg(var Message: TMsg): boolean;
- begin { TMDIApplication.ProcessAppMsg }
- ProcessAppMsg := ProcessMDIAccels(Message) or
- ProcessDlgMsg (Message) or
- ProcessAccels (Message)
- end { TMDIApplication.ProcessAppMsg };
-
- {**********************************************************************
-
- TMDIDialog1 methods
-
- Done destructor. This routine destroys an instance of
- TMDIDialog1. It first frees the transfer buffer, then it calls
- TMDIDialog.Done to free the rest of the object.
-
- **********************************************************************}
-
- destructor TMDIDialog1.Done;
- begin { TMDIDialog1.Done }
- FreeMem(TheDialog^.TransferBuffer, sizeof(Dlg1XferBuffer));
- TMDIDialog.Done
- end { TMDIDialog1.Done };
-
- {**********************************************************************
-
- Init constructor. This routine initializes the fields we've
- added to the inherited set and then calls the inherited
- constructor to build the window.
-
- **********************************************************************}
-
- constructor TMDIDialog1.Init(AParent: PWindowsObject;
- ATitle : PChar;
- ANumber: integer);
- begin { TMDIDialog1.Init }
- with MDIApplication do
- TMDIDialog.Init(AParent, ATitle, EditMenu, EditPos);
- Attr.ID := ANumber
- end { TMDIDialog1.Init };
-
- {**********************************************************************
-
- InitDialog method. This method is an override of the TMDIDialog
- method. It allocates memory for a transfer buffer for the
- dialog box, then initializes the buffer. It finally creates
- the dialog box OWL object & returns its address to the caller.
-
- **********************************************************************}
-
- function TMDIDialog1.InitDialog: PDlgWindow;
- var
- Buffer: PDlg1XFerBuffer;
-
- begin { TMDIDialog1.InitDialog }
- GetMem(Buffer, sizeof(Dlg1XferBuffer));
- FillChar(Buffer^, sizeof(Dlg1XferBuffer), 0);
- InitDialog := PDlgWindow(New(PDialog1, Init(@Self, Dlg1Name, Buffer)))
- end { TMDIDialog1.InitDialog };
-
- {**********************************************************************
-
- These two methods are standard for changing the window class's
- characteristics. In this case, we name the class "Dialog1".
- We also set the class's icon to the icon we created in the
- resource file. This allows us to use the standard windows
- code for dealing with a minimized instance of this class!
-
- **********************************************************************}
-
- function TMDIDialog1.GetClassName: PChar;
- begin { TMDIDialog1.GetClassName }
- GetClassName := Dlg1Name
- end { TMDIDialog1.GetClassName };
-
- procedure TMDIDialog1.GetWindowClass(var AWndClass: TWndClass);
- begin { TMDIDialog1.GetWindowClass }
- TMDIChild.GetWindowClass(AWndClass);
- AWndClass.hIcon := LoadIcon(HInstance, Dlg1Name)
- end { TMDIDialog1.GetWindowClass };
-
- {**********************************************************************
-
- This method sets up the dialog window's child number static
- field so that it has the right number.
-
- **********************************************************************}
-
- procedure TMDIDialog1.SetupWindow;
- var
- NumStr: string[6];
-
- begin { TMDIDialog1.SetupWindow }
- TMDIDialog.SetupWindow;
- Str(Attr.ID:1, NumStr);
- StrPCopy(PDlg1XferBuffer(TheDialog^.TransferBuffer)^.Number, NumStr);
- with PDialog1(TheDialog)^ do
- Static^.Transfer(TransferBuffer, tf_SetData)
- end { TMDIDialog1.SetupWindow };
-
- {**********************************************************************
-
- This method sets up the edit menu to reflect the ability of
- any edit control to fulfill an editing command.
-
- **********************************************************************}
-
- procedure TMDIDialog1.wmInitMenuPopup(var Msg: TMessage);
- var
- Wnd: HWnd;
-
- begin { TMDIDialog1.wmInitMenuPopup }
- if Msg.lParam = 1
- then
- begin
- Wnd := GetFocus;
- if IsChild(TheDialog^.HWindow, Wnd)
- then InitEditMenu(Wnd, Msg)
- end;
- Msg.result := 0
- end { TMDIDialog1.wmInitMenuPopup };
-
- {**********************************************************************
-
- TMDIDialog2 methods
-
- Done destructor. This routine destroys an instance of
- TMDIDialog2. It first frees the transfer buffer, then it calls
- TMDIDialog.Done to free the rest of the object.
-
- **********************************************************************}
-
- destructor TMDIDialog2.Done;
- begin { TMDIDialog2.Done }
- FreeMem(TheDialog^.TransferBuffer, sizeof(Dlg2XferBuffer));
- TMDIDialog.Done
- end { TMDIDialog2.Done };
-
- {**********************************************************************
-
- Init constructor. This routine initializes the fields we've
- added to the inherited set and then calls the inherited
- constructor to build the window.
-
- **********************************************************************}
-
- constructor TMDIDialog2.Init(AParent: PWindowsObject;
- ATitle : PChar;
- ANumber: integer);
- begin { TMDIDialog2.Init }
- with MDIApplication do
- TMDIDialog.Init(AParent, ATitle, EditMenu, EditPos);
- Attr.ID := ANumber
- end { TMDIDialog2.Init };
-
- {**********************************************************************
-
- InitDialog method. This method is an override of the TMDIDialog
- method. It allocates memory for a transfer buffer for the
- dialog box, then initializes the buffer. It finally creates
- the dialog box OWL object & returns its address to the caller.
-
- **********************************************************************}
-
- function TMDIDialog2.InitDialog: PDlgWindow;
- var
- Buffer: PDlg2XferBuffer;
-
- begin { TMDIDialog2.InitDialog }
- GetMem(Buffer, sizeof(Dlg2XferBuffer));
- FillChar(Buffer^, sizeof(Dlg2XferBuffer), 0);
- InitDialog := PDlgWindow(New(PDialog2, Init(@Self, Dlg2Name, Buffer)))
- end { TMDIDialog2.InitDialog };
-
- {**********************************************************************
-
- These two methods are standard for changing the window class's
- characteristics. In this case, we name the class "Dialog2".
- We also set the class's icon to the icon we created in the
- resource file. This allows us to use the standard windows
- code for dealing with a minimized instance of this class!
-
- **********************************************************************}
-
- function TMDIDialog2.GetClassName: PChar;
- begin { TMDIDialog2.GetClassName }
- GetClassName := Dlg2Name
- end { TMDIDialog2.GetClassName };
-
- procedure TMDIDialog2.GetWindowClass(var AWndClass: TWndClass);
- begin { TMDIDialog2.GetWindowClass }
- TMDIChild.GetWindowClass(AWndClass);
- AWndClass.hIcon := LoadIcon(HInstance, Dlg2Name)
- end { TMDIDialog2.GetWindowClass };
-
- {**********************************************************************
-
- This method sets up the dialog window's child number static
- field so that it has the right number.
-
- **********************************************************************}
-
- procedure TMDIDialog2.SetupWindow;
- var
- NumStr: string[6];
-
- begin { TMDIDialog2.SetupWindow }
- TMDIDialog.SetupWindow;
- Str(Attr.ID:1, NumStr);
- StrPCopy(PDlg1XferBuffer(TheDialog^.TransferBuffer)^.Number, NumStr);
- with PDialog2(TheDialog)^ do
- Static^.Transfer(TransferBuffer, tf_SetData)
- end { TMDIDialog2.SetupWindow };
-
- {**********************************************************************
-
- This method sets up the edit menu to reflect the ability of
- any edit control to fulfill an editing command.
-
- **********************************************************************}
-
- procedure TMDIDialog2.wmInitMenuPopup(var Msg: TMessage);
- var
- Wnd: HWnd;
-
- begin { TMDIDialog2.wmInitMenuPopup }
- if Msg.lParam = 1
- then
- begin
- Wnd := GetFocus;
- if IsChild(TheDialog^.HWindow, Wnd)
- then InitEditMenu(Wnd, Msg)
- end;
- Msg.result := 0
- end { TMDIDialog2.wmInitMenuPopup };
-
- {**********************************************************************
-
- TMDIEditChild methods
-
- Done destructor. It first destroys the edit control child
- window and then destroys itself.
-
- **********************************************************************}
-
- destructor TMDIEditChild.Done;
- begin { TMDIEditChild.Done }
- dispose(TheEdit, Done);
- TMDIChild.Done
- end { TMDIEditChild.Done };
-
- {**********************************************************************
-
- Init constructor. This routine initializes the fields we've
- added to the inherited set and then calls the inherited
- constructor to build the window.
-
- **********************************************************************}
-
- constructor TMDIEditChild.Init(AParent: PWindowsObject;
- ATitle : PChar;
- ANumber: integer);
- begin { TMDIEditChild.Init }
- with MDIApplication do
- TMDIChild.Init(AParent, ATitle, EditMenu, EditPos);
- Attr.ID := ANumber;
- TheEdit := New(PEdit, Init(@Self, 100, nil, 0, 0, 0, 0, 0, TRUE))
- end { TMDIEditChild.Init };
-
- {**********************************************************************
-
- These two methods are standard for changing the window class's
- characteristics. In this case, we name the class "EditCtrl".
- We also set the class's icon to the icon we created in the
- resource file. This allows us to use the standard windows
- code for dealing with a minimized instance of this class!
-
- **********************************************************************}
-
- function TMDIEditChild.GetClassName: PChar;
- begin { TMDIEditChild.GetClassName }
- GetClassName := EditName
- end { TMDIEditChild.GetClassName };
-
- procedure TMDIEditChild.GetWindowClass(var AWndClass: TWndClass);
- begin { TMDIDialog1.GetWindowClass }
- TWindow.GetWindowClass(AWndClass);
- AWndClass.hIcon := LoadIcon(HInstance, EditName)
- end { TMDIEditChild.GetWindowClass };
-
- {**********************************************************************
-
- This method sets up the edit menu to reflect the ability of
- any edit control to fulfill an editing command.
-
- **********************************************************************}
-
- procedure TMDIEditChild.wmInitMenuPopup(var Msg: TMessage);
- begin { TMDIEditChild.wmInitMenuPopup }
- if Msg.lParam = 1
- then InitEditMenu(TheEdit^.HWindow, Msg);
- Msg.result := 0
- end { TMDIEditChild.wmInitMenuPopup };
-
- {**********************************************************************
-
- The window has received the input focus. We don't want it.
- This method passes the focus to its child edit control window.
-
- **********************************************************************}
-
- procedure TMDIEditChild.wmSetFocus(var Msg: TMessage);
- begin { TMDIEditChild.wmSetFocus }
- if TheEdit^.HWindow <> 0
- then SetFocus(TheEdit^.HWindow);
- Msg.result := 0
- end { TMDIEditChild.wmSetFocus };
-
- {**********************************************************************
-
- This method makes sure that the edit child control window
- always occupies the entire area of the MDI child window.
-
- **********************************************************************}
-
- procedure TMDIEditChild.wmSize(var Msg: TMessage);
- begin { TMDIEditChild.wmSize }
- if TheEdit^.HWindow <> 0
- then MoveWindow(TheEdit^.HWindow, 0, 0, LoWord(Msg.lParam),
- HiWord(Msg.lParam), TRUE);
- TMDIChild.wmSize(Msg)
- end { TMDIEditChild.wmSize };
-
- {**********************************************************************
-
- TMDIFrame methods
-
- Init constructor. This routine initializes the fields we've
- added to the inherited set and then calls the inherited
- constructor to build the window.
-
- **********************************************************************}
-
- constructor TMyMDIFrame.Init(ATitle: PChar;
- APos : integer);
- begin { TMyMDIFrame.Init }
- TMDIFrame.Init(ATitle, 0);
- ChildMenuPos := APos;
- NoChildren := 0;
- DialogType := Dialog1
- end { TMyMDIFrame.Init };
-
- procedure TMyMDIFrame.SetupWindow;
- begin { TMyMDIFrame.SetupWindow }
- TMDIFrame.SetupWindow;
- Attr.Menu := GetMenu(HWindow)
- end { TMyMDIFrame.SetupWindow };
-
- {**********************************************************************
-
- These two methods are standard for changing the window class's
- characteristics. In this case, we name the class "MDIExample".
- We also set the class's icon to the icon we created in the
- resource file.
-
- **********************************************************************}
-
- function TMyMDIFrame.GetClassName: PChar;
- begin { TMyMDIFrame.GetClassName }
- GetClassName := AppName
- end { TMyMDIFrame.GetClassName };
-
- procedure TMyMDIFrame.GetWindowClass(var AWndClass: TWndClass);
- begin { TMyMDIFrame.GetWindowClass }
- TMDIFrame.GetWindowClass(AWndClass);
- AWndClass.lpszMenuName := AppName;
- AWndClass.hbrBackground := color_AppWorkspace + 1;
- AWndClass.hIcon := LoadIcon(HInstance, AppName)
- end { TMyMDIFrame.GetWindowClass };
-
- {**********************************************************************
-
- These methods handle menu command selection. They get the
- proper events rolling whenever the user uses one of the commands.
-
- The idea is that when the user specifies that a particular
- type of child window should be created, we save an apropriate
- value in the frame window's DialogType field. This records
- exactly what we should be doing.
-
- Other commands are implemented in other ways.
-
- **********************************************************************}
-
- procedure TMyMDIFrame.idCloseChild(var Msg: TMessage);
- var
- NChild: integer;
- Handle: HWnd;
- Child : PWindowsObject;
-
- begin { TMyMDIFrame.idCloseChild }
- Handle := LoWord(SendMessage(GetClient^.HWindow, wm_MDIGetActive, 0, 0));
- Child := GetChild(Handle);
- CloseChild(Child);
- dec(NoChildren)
- end { TMyMDIFrame.idCloseChild };
-
- procedure TMyMDIFrame.idDialog1(var Msg: TMessage);
- begin { TMyMDIFrame.idDialog1 }
- DialogType := Dialog1;
- CreateChild
- end { TMyMDIFrame.idDialog1 };
-
- procedure TMyMDIFrame.idDialog2(var Msg: TMessage);
- begin { TMyMDIFrame.idDialog2 }
- DialogType := Dialog2;
- CreateChild
- end { TMyMDIFrame.idDialog2 };
-
- procedure TMyMDIFrame.idEditCtrl(var Msg: TMessage);
- begin { TMyMDIFrame.idEditCtrl }
- DialogType := EditCtrl;
- CreateChild
- end { TMyMDIFrame.idDialog2 };
-
- procedure TMyMDIFrame.idRandRect(var Msg: TMessage);
- begin { TMyMDIFrame.idRandRect }
- DialogType := RandRect;
- CreateChild
- end { TMyMDIFrame.idRandRect };
-
- {**********************************************************************
-
- This method creates the appropriate MDI child window by testing
- the value of the frame window's DialogType field. The idea is
- that we need to make sure that the proper type of child window
- is created, and we only have one routine that can do it, so
- we test the value of the field to figure out which type to
- create.
-
- **********************************************************************}
-
- function TMyMDIFrame.InitChild: PWindowsObject;
- var
- Num : Integer;
- Temp : string[31];
- Title: array [0 .. 32] of char;
- Temp2: array [0 .. 10] of char;
-
-
- function NumberUsed(P: PWindow): Boolean; far;
- begin { NumberUsed }
- NumberUsed := Num = P^.Attr.ID
- end { NumberUsed };
-
- begin { TMyMDIFrame.InitChild }
- Inc(NoChildren);
- Num := 1;
- while FirstThat(@NumberUsed) <> nil do
- Inc(Num);
- StrCopy(Title, ChildTitles[DialogType]);
- Str(Num:1, Temp);
- StrCat(Title, StrPCopy(Temp2, Temp));
- case DialogType of
- Dialog1 : InitChild := New(PMDIDialog1 , Init(@Self, Title, Num));
- Dialog2 : InitChild := New(PMDIDialog2 , Init(@Self, Title, Num));
- RandRect: InitChild := New(PRandRect , Init(@Self, Title, Num));
- EditCtrl: InitChild := New(PMDIEditChild, Init(@Self, Title, Num))
- end
- end { TMyMDIFrame.InitChild };
-
- {**********************************************************************
-
- TRandRect methods
-
- Init constructor. This routine initializes the fields we've
- added to the inherited set and then calls the inherited
- constructor to build the window.
-
- **********************************************************************}
-
- constructor TRandRect.Init(AParent: PWindowsObject;
- ATitle : PChar;
- ANumber: integer);
- begin { TRandRect.Init }
- with MDIApplication do
- TMDIChild.Init(AParent, ATitle, RectMenu, RectPos);
- Attr.ID := ANumber
- end { TRandRect.Init };
-
- {**********************************************************************
-
- These two methods are standard for changing the window class's
- characteristics. In this case, we name the class "RandRect".
- We also set the class's icon to the icon we created in the
- resource file. This allows us to use the standard windows
- code for dealing with a minimized instance of this class!
-
- **********************************************************************}
-
- function TRandRect.GetClassName: PChar;
- begin { TMDIEditChild.GetClassName }
- GetClassName := RandName
- end { TMDIRandRect.GetClassName };
-
- procedure TRandRect.SetupWindow;
- begin { TRandRect.SetupWindow }
- TMDIChild.SetupWindow;
- SetTimer(HWindow, 1, 250, nil)
- end { TRandRect.SetupWindow };
-
- {**********************************************************************
-
- The following methods were taken from Charles Petzold's MDI
- Demo example program and translated to OWL.
-
- **********************************************************************}
-
- procedure TRandRect.wmDestroy(var Msg: TMessage);
- begin { TRandRect.wmDestroy }
- KillTimer(HWindow, 1);
- TWindow.wmDestroy(Msg)
- end { TRandRect.wmDestroy };
-
- procedure TRandRect.wmPaint(var Msg: TMessage);
- var
- DC: HDC;
- PS: TPaintStruct;
-
- begin { TRandRect.Paint }
- InvalidateRect(HWindow, nil, TRUE);
- DC := BeginPaint(HWindow, PS);
- EndPaint(HWindow, PS);
- Msg.Result := 0
- end { TRandRect.Paint };
-
- procedure TRandRect.wmTimer(var Msg: TMessage);
- var
- Brush ,
- OBrush : HBrush;
- DC : HDC;
- Blue ,
- Green ,
- Red ,
- xLeft ,
- xRight ,
- yTop ,
- yBottom: integer;
-
- function Max(a, b: integer): integer;
- begin { Max }
- if a > b
- then Max := a
- else Max := b
- end { Max };
-
- function Min(a, b: integer): integer;
- begin { Min }
- if a < b
- then Min := a
- else Min := b
- end { Min };
-
- begin { TRandRect.wmTimer }
- xLeft := round(random * Attr.W);
- xRight := round(random * Attr.W);
- yTop := round(random * Attr.H);
- yBottom := round(random * Attr.H);
- Blue := round(random * 255);
- Green := round(random * 255);
- Red := round(random * 255);
-
- DC := GetDC(HWindow);
- Brush := CreateSolidBrush(RGB(Red, Green, Blue));
- OBrush := SelectObject(DC, Brush);
- Rectangle(DC, min(xLeft, xRight), min(yTop, yBottom),
- max(xLeft, xRight), max(yTop, yBottom));
- SelectObject(DC, OBrush);
- DeleteObject(Brush);
- ReleaseDC(HWindow, DC);
- Msg.Result := 0
- end { TRandRect.wmTimer };
-
- {**********************************************************************
-
- Main program. Initialize the program, run the message loop,
- then shut it down.
-
- **********************************************************************}
-
- begin { MDIExample }
- Randomize;
- MDIApplication.Init(AppName);
- MDIApplication.Run;
- MDIApplication.Done
- end { MDIExample }.